package com.example.base.websocket.plugin;

import com.example.base.websocket.AppWebSocket;
import org.springframework.stereotype.Component;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

@Component
public class AppWebSocketMap {

    private Map<String, AppWebSocket> APP_WEBSOCKET_MAP;

    public void addAppWebSocket(String appName,AppWebSocket appWebSocket){
        if(APP_WEBSOCKET_MAP==null){
            APP_WEBSOCKET_MAP=new ConcurrentHashMap<>();
        }
        APP_WEBSOCKET_MAP.put(appName,appWebSocket);
    }

    public List<AppWebSocket> getAppWebSocketList(){
        List<AppWebSocket> appWebSockets = new ArrayList<>(APP_WEBSOCKET_MAP.values());
        return appWebSockets;
    }
}
